/*
 * RestaurantesConverter.java
 *
 * Created on 3 de Dezembro de 2007, 08:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.no_ip.gerson.persistencia;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author gerson.albuquerque
 */
public class RestaurantesConverter implements Converter {
    
    /** Creates a new instance of RestaurantesConverter */
    public RestaurantesConverter() {
    }

    public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) {
        if (string == null) {
            return null;
        }
        Integer id = new Integer(string);
        RestaurantesController controller = (RestaurantesController) facesContext.getApplication().getVariableResolver().resolveVariable(
            facesContext, "restaurantes");
        
        return controller.findRestaurantes(id);
    }

    public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) {
        if (object == null) {
            return null;
        }
        if(object instanceof Restaurantes) {
            Restaurantes o = (Restaurantes) object;
            return "" + o.getId();
        } else {
            throw new IllegalArgumentException("object:" + object + " of type:" + object.getClass().getName() + "; expected type: com.no_ip.gerson.persistencia.Restaurantes");
        }
    }
    
}
